﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace 控制台应用
{
    public class FaZhuBianCi
    {
        DBHelper dbHelper = new DBHelper();

        #region 获取发注逻辑的开始时间
        /// <summary>
        /// 获取发注逻辑的开始时间
        /// </summary>
        /// <param name="strPackSpot">包装工厂</param>
        /// <returns></returns>
        public DataTable GetFaZhuTimeDT(string strPackSpot)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.AppendLine("    select a.vcPackSpot,a.vcFaZhuID,isnull(b.dEnd ,a.dFrom) as dEnd  from           \n");
                strSql.AppendLine("    (           \n");
                strSql.AppendLine("       select distinct vcPackSpot,vcFaZhuID,dFrom from TPackFaZhuTime  where vcPackSpot='" + strPackSpot + "' and (dFrom<GETDATE() and dTo>GETDATE() )        \n");
                strSql.AppendLine("    )a           \n");
                strSql.AppendLine("    left join           \n");
                strSql.AppendLine("    (           \n");
                strSql.AppendLine("       select a.vcPackSpot,a.vcFaZhuID,max(dEnd) as dEnd from TPackCompute_Time a      \n");
                strSql.AppendLine("      inner join      \n");
                strSql.AppendLine("      (      \n");
                strSql.AppendLine("         select distinct vcFlag from TPackCompute where vcOrderNo is not null      \n");
                strSql.AppendLine("      )b on a.vcFlag=b.vcFlag      \n");
                strSql.AppendLine("   	   group by  vcPackSpot,vcFaZhuID           \n");
                strSql.AppendLine("    )b on   a.vcPackSpot=b.vcPackSpot and a.vcFaZhuID=b.vcFaZhuID           \n");
                return dbHelper.ExcuteSqlWithSelectToDT(strSql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 发注便次更新
        public DataTable GetBianCiDT(string strPackSpot)
        {
            DataTable faZhuTimeDT = GetFaZhuTimeDT(strPackSpot);        //

            return null;
        }

        #endregion
    }
}
